#include "opengl-330.hh"
#include "../utils/journal.hh"
#include "../utils/gl-debug.hh"
#include "../lib/gl.hh"
#include <cmath>
#include <string>

namespace ngintoy
{
    namespace renderer
    {
        namespace {
            static renderer::registrar<opengl_330> _{"opengl-330"};

            using jn = utils::journal;
            using namespace std::literals;
        }


        opengl_330::opengl_330(config & conf, platform & plat)
            : gl{conf, plat}
        {
            jn::begin() << "opengl-330 renderer";

            gl_plat.make_context(3, 3);

            auto info = jn::info(" ren ");
            info << "current context"
                 << "  - vendor  : "s + reinterpret_cast<char const*>(glGetString(GL_VENDOR))
                 << "  - version : "s + reinterpret_cast<char const*>(glGetString(GL_VERSION))
                 << "  - renderer: "s + reinterpret_cast<char const*>(glGetString(GL_RENDERER))
                 << "  - glsl    : "s + reinterpret_cast<char const*>(glGetString(GL_SHADING_LANGUAGE_VERSION));

            utils::gl_debug();
        }

        opengl_330::~opengl_330()
        {
            jn::end() << "opengl-330 renderer";
        }

        void opengl_330::render()
        {
            glClearColor(std::fmod(gl_plat.now(), 1), 0, 0, 1);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        }
    }
}

